// https://nuxt.com/docs/api/configuration/nuxt-config

import { NuxtPage } from "nuxt/schema";
import { loadEnv } from 'vite'

interface VITE_ENV_CONFIG {
    VITE_ENV: string,
    VITE_APP_API_URL: string,
}
const eneString = process.env.npm_lifecycle_script || ''
const envScript = eneString.split(' ')
const envName = envScript[envScript.length - 1] // 通过启动命令区分环境
const envData = loadEnv(envName, process.cwd()) as unknown as VITE_ENV_CONFIG
// console.log('当前环境：', eneString, envName === 'prod' ? '正式环境' : '测试环境')
export default defineNuxtConfig({
    srcDir: 'src/',
    typescript: {
        strict: true
    },
    // 将环境变量设置到 runtimeConfig 当中
    runtimeConfig: {
        public: envData
    },
    modules: ['@pinia/nuxt'],
    // 设置body class
    head: {
        bodyAttrs: {
            class: 'body-class'
        },
    },
    vite: {
        css: {
            preprocessorOptions: {
                scss: {
                    additionalData: '@import "@/assets/styles/variable.scss";'
                }
            }
        }
    },
    hooks: {
        // 自定义路由
        'pages:extend'(pages: NuxtPage[] = []) {
            const pagesToDuplicate = pages.filter(page => page.path.startsWith('/pc'))
            pagesToDuplicate.forEach(page => {
                pages.splice(pages.findIndex(v => v.file == page.file), 1)
                pages.push({
                    ...page,
                    path: `${page.path.replace('/pc', '')}`,
                    name: `${page.name}`
                })
            })
        }
    },
    devServer: {
        host: 'gametest.leiting.com',
        port: 3000,
        // open: true,
        // strictPort: false,
        // https: true
    }
})


